<style lang="less">
  @import './login.less';
</style>

<template>
  <div class="login">
    <div class="login-con">
      <div class="login-logo">
        <img src="static/img/sign-in-logo.png" />
      </div>
      <div class="form-con">
        <login-form @on-success-valid="handleSubmit"></login-form>
      </div>
    </div>
  </div>
</template>


<script>
import LoginForm from '_c/login-form'
import { mapActions } from 'vuex'
import { setToken, getToken } from '@/libs/utils'
export default {
  name: 'Login',
  metaInfo:{
    title:'火币量化交易',
    titleTemplate: '%s |登录 ',
    meta: [
      { charset: 'utf-8' },
      { name: 'description', content: 'foo' },
      {keyword: '量化交易'}
    ]
  },
  components: {
    LoginForm
  },
  created(){
    if(getToken()){ //判断是否有token
      this.getUserInfo().then(res => {
        this.$router.push({
          path:'/trade'
        })
      }).catch(err =>{
        console.log(err)
      })
    }
  },
  methods: {
    ...mapActions([
      'handleLogin',
      'getUserInfo'
    ]),
    handleSubmit ({ name, password,googlekey }) {
      this.handleLogin({ name, password,googlekey }).then(res => {
        this.$Message.success("登录成功！");
        this.getUserInfo().then(res => {
          this.$router.push({
            path:'/trade'
          })
        })
      }).catch(err =>{
        this.$Message.error(err);
      })
    }
  }
}
</script>

<style  scoped lang="less">

</style>
